import { IMenu } from "@/views/system/menu/types";

export interface IMenuList {
    name: string;
    value: string;
}
export interface IIconList extends IMenuList { };

//获取views下面的所有页面路径（除components)
export const getMenuList = (): IMenu[] => {
    let files = import.meta.glob(['@/views/**/*.tsx'], { eager: true });
    let menuList: IMenu[] = [];
    for (const file in files) {
        if (!file.includes('components') && !file.includes('column')) {
            let filePath = file.substring(0, file.lastIndexOf("/"));
            let fileName = filePath.substring(filePath.lastIndexOf("/") + 1);
            let path = file.substring(10, file.lastIndexOf(".tsx"));
            menuList.push({
                name: fileName,
                value: path
            })
        }
    }
    return menuList;
}

//获取icons下的所有svg
export const getIconList = (): IIconList[] => {
    let files = import.meta.glob(['@/icons/**/*.svg'], { eager: true });
    let iconList: IIconList[] = [];
    for (const file in files) {
        let svgPath = file.substring(file.lastIndexOf("icons/") + 6, file.lastIndexOf("."));
        let svgName = file.substring(file.lastIndexOf("/") + 1, file.lastIndexOf("."));
        iconList.push({
            name: svgName,
            value: svgPath
        })
    }
    return iconList;
}